package org.lanqiao.tjut.action;

import java.util.List;

import org.lanqiao.tjut.orm.UsersEntity;
import org.lanqiao.tjut.service.IUserService;
import org.lanqiao.tjut.service.impl.UserServiceImpl;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/*
	 * 定义aciton对象变量，为该对象提供getter/setter方法，
	 * 并保证前台jsp页面form表单控件name属性的值和该pojo实体类的属性名 保持一致，则可以自动进行类型转换
	 */
	private UsersEntity userE;
	// spring 依赖注入
	private IUserService userS;

	public String doLogin() {
		// 调用service层进行用户登录信息验证
		List<UsersEntity> lstUsers = userS.selectUsersInfo4Login(userE);
		// 验证是否登录成功
		if (lstUsers != null && lstUsers.size() > 0) {
			// 登录成功
			System.out.println("登录用户：" + userE.getUsername());
			// 将用户信息进行缓存处理(session级别)
			ActionContext.getContext().getSession().put("loginedUserInfo", lstUsers.get(0));
			// 返回结果串
			return this.SUCCESS;
		}
		// 验证失败
		return "failed";
	}

	public UsersEntity getUserE() {
		return userE;
	}

	public void setUserE(UsersEntity userE) {
		this.userE = userE;
	}

	public void setUserS(IUserService userS) {
		this.userS = userS;
	}

}
